//
//  LineDownViewController.m
//  dmao-customer
//
//  Created by macbook on 2017/10/12.
//  Copyright © 2017年 秦慕乔. All rights reserved.
//

#import "LineDownViewController.h"
#import "LineDownHomeTCell.h"
#import "LDAllClassViewController.h"
#import "LDHomeNextViewController.h"
#import "LDStoreViewController.h"
#import "LDSearchViewController.h"
#import "ChooseCityController.h"
@interface LineDownViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSArray *_citys;
}
@property (weak, nonatomic) IBOutlet UIView *TopView;
@property (weak, nonatomic) IBOutlet UILabel *cityLabel;
@property (weak, nonatomic) IBOutlet UILabel *FirstLabel;
@property (weak, nonatomic) IBOutlet UILabel *SecondLabel;
@property (weak, nonatomic) IBOutlet UILabel *ThirdLabel;
@property (weak, nonatomic) IBOutlet UILabel *FourthLabel;
@property (weak, nonatomic) IBOutlet UILabel *FifthLabel;
@property (weak, nonatomic) IBOutlet UILabel *SixthLabel;
@property (weak, nonatomic) IBOutlet UILabel *SeventhLabel;
@property (weak, nonatomic) IBOutlet UILabel *EigthLabel;
@property (strong, nonatomic) UITableView * LineDownTable;
@property (strong, nonatomic) UIView *footerView;
@property (strong, nonatomic) NSMutableArray *ListArr;
@property (copy, nonatomic) NSString *classId1;
@property (copy, nonatomic) NSString *classId2;
@property (copy, nonatomic) NSString *classId3;
@property (copy, nonatomic) NSString *classId4;
@property (copy, nonatomic) NSString *classId5;
@property (copy, nonatomic) NSString *classId6;
@property (copy, nonatomic) NSString *classId7;
@end

@implementation LineDownViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    _ListArr = [[NSMutableArray alloc] init];
    _citys  = [NSArray array];
    [self downloadData];
    [self createFooterView];
    [self createTableView];
}

- (void)downloadData
{
    [self.view loadingOnAnyView];
    NSDictionary *dic = @{@"jwd":[Utils getJWD]};
    [THWManager PostHttp:API(LineDownHome) Parameters:dic Success:^(id responseObject) {
        [self.view removeAnyView];
        NSMutableArray *TopArr = [[Utils getData:responseObject] objectForKey:@"class"];
        
        _citys = [[Utils getData:responseObject] objectForKey:@"city"];
        _FirstLabel.text = [NSString stringWithFormat:@"%@", [TopArr objectAtIndex:0][@"class_name"]];
        _classId1 = [TopArr objectAtIndex:0][@"class_id"];
        _SecondLabel.text = [NSString stringWithFormat:@"%@", [TopArr objectAtIndex:1][@"class_name"]];
        _classId2 = [TopArr objectAtIndex:1][@"class_id"];
        _ThirdLabel.text = [NSString stringWithFormat:@"%@", [TopArr objectAtIndex:2][@"class_name"]];
        _classId3 = [TopArr objectAtIndex:2][@"class_id"];
        _FourthLabel.text = [NSString stringWithFormat:@"%@", [TopArr objectAtIndex:3][@"class_name"]];
        _classId4 = [TopArr objectAtIndex:3][@"class_id"];
        _FifthLabel.text = [NSString stringWithFormat:@"%@", [TopArr objectAtIndex:4][@"class_name"]];
        _classId5 = [TopArr objectAtIndex:4][@"class_id"];
        _SixthLabel.text = [NSString stringWithFormat:@"%@", [TopArr objectAtIndex:5][@"class_name"]];
        _classId6 = [TopArr objectAtIndex:5][@"class_id"];
        _SeventhLabel.text = [NSString stringWithFormat:@"%@", [TopArr objectAtIndex:6][@"class_name"]];
        _classId7 = [TopArr objectAtIndex:6][@"class_id"];
        _EigthLabel.text = [NSString stringWithFormat:@"%@", [TopArr objectAtIndex:7][@"class_name"]];
        
        _ListArr = [[[Utils getData:responseObject] objectForKey:@"list"] objectForKey:@"Rows"];
        [_LineDownTable reloadData];

    } andFalse:^(NSError *error) {
        [self.view removeAnyView];
    }];
}

- (void)createFooterView
{
    _footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 1)];
    _footerView.backgroundColor = RGB(232, 234, 234);
}

- (void)createTableView
{
    _LineDownTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 311, WIDTH, HEIGHT-311-49)];
    _LineDownTable.delegate = self;
    _LineDownTable.dataSource = self;
    [_LineDownTable registerNib:[UINib nibWithNibName:@"LineDownHomeTCell" bundle:nil] forCellReuseIdentifier:@"LineDownHomeTCell"];
    [_LineDownTable setTableFooterView:_footerView];
    _LineDownTable.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_LineDownTable];
}

- (IBAction)ChooseCity:(UIButton *)sender {
    ChooseCityController *choose = [[ChooseCityController alloc]init];
    choose.data = _citys;
    choose.backType = ^(NSString *city) {
        _cityLabel.text = city;
    };
    choose.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:choose animated:YES];
}
- (IBAction)SearchClick:(UIButton *)sender {
    LDSearchViewController *LDSear = [[LDSearchViewController alloc] init];
    LDSear.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:LDSear animated:YES];
}

- (IBAction)FirstClick:(UIButton *)sender {
    LDHomeNextViewController *next = [[LDHomeNextViewController alloc] init];
    next.hidesBottomBarWhenPushed = YES;
    next.titleStr = _FirstLabel.text;
    next.classId = _classId1;
    [self.navigationController pushViewController:next animated:YES];
}

- (IBAction)SecondClick:(UIButton *)sender {
    LDHomeNextViewController *next = [[LDHomeNextViewController alloc] init];
    next.hidesBottomBarWhenPushed = YES;
    next.titleStr = _SecondLabel.text;
    next.classId = _classId2;
    [self.navigationController pushViewController:next animated:YES];
}

- (IBAction)ThirdClick:(UIButton *)sender {
    LDHomeNextViewController *next = [[LDHomeNextViewController alloc] init];
    next.hidesBottomBarWhenPushed = YES;
    next.titleStr = _ThirdLabel.text;
    next.classId = _classId3;
    [self.navigationController pushViewController:next animated:YES];
}

- (IBAction)FourthClick:(UIButton *)sender {
    LDHomeNextViewController *next = [[LDHomeNextViewController alloc] init];
    next.hidesBottomBarWhenPushed = YES;
    next.titleStr = _FourthLabel.text;
    next.classId = _classId4;
    [self.navigationController pushViewController:next animated:YES];
}

- (IBAction)FifthClick:(UIButton *)sender {
    LDHomeNextViewController *next = [[LDHomeNextViewController alloc] init];
    next.hidesBottomBarWhenPushed = YES;
    next.titleStr = _FifthLabel.text;
    next.classId = _classId5;
    [self.navigationController pushViewController:next animated:YES];
}

- (IBAction)SixthClick:(UIButton *)sender {
    LDHomeNextViewController *next = [[LDHomeNextViewController alloc] init];
    next.hidesBottomBarWhenPushed = YES;
    next.titleStr = _SixthLabel.text;
    next.classId = _classId6;
    [self.navigationController pushViewController:next animated:YES];
}

- (IBAction)SevenClick:(UIButton *)sender {
    LDHomeNextViewController *next = [[LDHomeNextViewController alloc] init];
    next.hidesBottomBarWhenPushed = YES;
    next.titleStr = _SeventhLabel.text;
    next.classId = _classId7;
    [self.navigationController pushViewController:next animated:YES];
}

- (IBAction)EigthClick:(UIButton *)sender {
    LDAllClassViewController *all = [[LDAllClassViewController alloc] init];
    all.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:all animated:YES];
}
- (IBAction)NearbyClick:(UIButton *)sender {
    LDHomeNextViewController *next = [[LDHomeNextViewController alloc] init];
    next.hidesBottomBarWhenPushed = YES;
    next.titleStr = @"所有商家";
    next.classId = @"0";
    [self.navigationController pushViewController:next animated:YES];
}

#pragma mark - UITableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _ListArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LineDownHomeTCell*cell = [tableView dequeueReusableCellWithIdentifier:@"LineDownHomeTCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[LineDownHomeTCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"LineDownHomeTCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell cellConfigureModel:_ListArr[indexPath.row]];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 111;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LDStoreViewController *store = [[LDStoreViewController alloc] init];
    store.hidesBottomBarWhenPushed = YES;
    store.lineId = [_ListArr[indexPath.row] objectForKey:@"lineId"];
    [self.navigationController pushViewController:store animated:YES];
}

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
